package DynamicProxy.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 代理处理器, 当执行target所有方法时，都是通过invoke中method.invoke执行的
 */
public class MyShellHandler implements InvocationHandler {

    private Object target = null;

    public MyShellHandler(Object target){
        this.target = target;
    }


    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object res = null;
        res = method.invoke(target,args);

        //功能增强
        if(res!=null){
            Float price = (Float) res;
            price+=25;
            res = price;
        }
        System.out.println("商家返还优惠卷");
        return res;
    }

}
